home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 12.6 KB | 425 lines | [TEXT/CWIE] |
- //
- // This is sample code which will make QTVR object movies from Linear QuickTime movies.
- //
- // © 1991-1996 Apple Computer, Inc. All rights reserved.
- //
-
- #include "MakeQTVRObject.h"
- #include "extern.h"
-
-
- #include <Dialogs.h>
-
- void InitDialogBox(DialogPtr askBox,QTVRObjectFileFormat1x0Record *fileFormat)
- {
- Handle iHandle;
- short iType;
- Rect iRect;
- Str255 textStr;
-
- // Initialize dialog data items before display
- GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kStandardObject);
-
- GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kOldNavigableMovieScene);
-
- GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kObjectInScene);
-
- NumToString (fileFormat->versionNumber, textStr);
- GetDItem (askBox, iVersionNumber, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString((float)(fileFormat->numberOfColumns),&textStr,0);
- GetDItem (askBox, iNumberOfColumns, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString((float)(fileFormat->numberOfRows),&textStr,0);
- GetDItem (askBox, iNumberOfRows, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString((float)(fileFormat->loopSize),&textStr,0);
- GetDItem (askBox, iLoopSize, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString((float)(fileFormat->loopTicks),&textStr,0);
- GetDItem (askBox, iLoopTicks, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString(Fix2Float(fileFormat->fieldOfView),&textStr,1);
- GetDItem (askBox, iFieldOfView, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString(Fix2Float(fileFormat->startHPan),&textStr,1);
- GetDItem (askBox, iStartHPan, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString(Fix2Float(fileFormat->endHPan),&textStr,1);
- GetDItem (askBox, iEndHPan, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString(Fix2Float(fileFormat->endVPan),&textStr,1);
- GetDItem (askBox, iEndVPan, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- FloatToString(Fix2Float(fileFormat->startVPan),&textStr,1);
- GetDItem (askBox, iStartVPan, &iType, &iHandle, &iRect);
- SetIText (iHandle, textStr);
-
- }
- //=================================================================================================
- // HandleMovieFormatDialog
- //-------------------------------------------------------------------------------------------------
- OSErr HandleMovieFormatDialog (MovieInstance *theInstance,Boolean applyValues)
- {
- DialogPtr askBox;
- Boolean boxDone = false;
- Handle iHandle;
- short hitItem,iType;
- Rect iRect;
- Str255 textStr;
- GWorldPtr saveGW;
- GDHandle saveGD;
- Boolean navControllerIsRunning = false,keepStartupViewInfo = false;
- QTVRObjectFileFormat1x0Record fileFormat;
- OSErr err;
- short versionNumber,movieType,numberOfColumns;
- short numberOfRows,loopSize,loopTicks;
- Fixed startHPan,endHPan,startVPan,endVPan;
- Fixed fieldOfView,initialHPan,initialVPan;
- TimeValue frameDur,posterViewTime;
- QTVRObjectFileFormat1x0Record currentObjectFormat;
- UserItemUPP outlineUPP = nil;
- ModalFilterUPP filterUPP = nil;
-
- askBox = GetNewDialog(kObjectDLOG, 0, (WindowPtr)-1);
- if (!askBox) return (MemError());
- InitCursor();
-
- outlineUPP = NewUserItemProc( OutlineOK );
- filterUPP = NewModalFilterProc(ModalFilter);
-
- // Install the OK outlining userProc
- GetDialogItem( askBox, 27, &iType, &iHandle, &iRect );
- SetDialogItem( askBox, 27, iType, (Handle) outlineUPP, &iRect );
-
- GetGWorld(&saveGW, &saveGD);
- SetGWorld((GWorldPtr)askBox,nil);
-
- if(!applyValues)
- {
- InitDialogBox(askBox, &gPrefInf.objectInfo);
- SetWTitle (askBox, "\pSet Preferences");
- }
- else
- {
- if(theInstance && theInstance->isObjectMovie)
- {
- GetQTVRObjectFileFormat1x0 (theInstance->movie,¤tObjectFormat);
- InitDialogBox(askBox, ¤tObjectFormat);
- }
- else
- InitDialogBox(askBox, &gPrefInf.objectInfo);
- SetWTitle (askBox, "\pAdd Object Data");
- }
-
- SelIText (askBox, iNumberOfRows, 0, 32767); // Select the first text box
- ShowWindow(askBox);
-
- while (!boxDone)
- {
-
- ModalDialog(filterUPP, &hitItem);
- GetDItem (askBox, hitItem, &iType, &iHandle, &iRect);
- switch (hitItem)
- {
- case iCancel:
- boxDone = true;
- break;
- case iUseObject:
- {
- Movie aMovie;
- FSSpec aSpec;
- short movieResFile,movieResID = 0;
- ControlHandle aHandle;
-
- GetDItem (askBox, iOK, &iType, (Handle*)&aHandle, &iRect);
- if(GetAMovie(&aSpec))
- {
- err = OpenMovieFile(&aSpec,&movieResFile,fsRdPerm);
- if(err != noErr)
- {
- UserMessage("\pCould not open the movie.");
- break;
- }
- err = NewMovieFromFile(&aMovie,movieResFile,&movieResID,nil,0,nil);
- if(err != noErr)
- {
- UserMessage("\pCould not create movie from movie file.");
- break;
- }
- if(!GetQTVRObjectFileFormat1x0 (aMovie,¤tObjectFormat))
- InitDialogBox(askBox, ¤tObjectFormat);
- CloseMovieFile(movieResFile);
- }
-
- SetGWorld (saveGW,saveGD);
- OutlineOK(askBox,iOK );
- }
- break;
- case iScene:
- SetCtlValue ((ControlHandle) iHandle, 1);
- GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- break;
- case iObjectInScene:
- SetCtlValue ((ControlHandle) iHandle, 1);
- GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- break;
- case iObject:
- SetCtlValue ((ControlHandle) iHandle, 1);
- GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
- SetCtlValue ((ControlHandle) iHandle, 0);
- break;
- case iOK:
- {
- long num;
-
- boxDone = true;
-
- GetDItem (askBox, iVersionNumber, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- StringToNum (textStr, &num);
- versionNumber = num;
-
- GetDItem (askBox, iNumberOfColumns, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- StringToNum (textStr, &num);
- numberOfColumns = (short)StringToFloat (textStr);;
-
- GetDItem (askBox, iNumberOfRows, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- numberOfRows = (short)StringToFloat (textStr);;
-
- GetDItem (askBox, iLoopSize, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- loopSize = (short)StringToFloat (textStr);
-
- GetDItem (askBox, iLoopTicks, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- loopTicks = (short)StringToFloat (textStr);;
-
- GetDItem (askBox, iStartHPan, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- startHPan = Float2Fix(StringToFloat (textStr));
-
- GetDItem (askBox, iEndHPan, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- endHPan = Float2Fix(StringToFloat (textStr));
-
- GetDItem (askBox, iStartVPan, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- startVPan = Float2Fix(StringToFloat (textStr));
-
- GetDItem (askBox, iEndVPan, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- endVPan = Float2Fix(StringToFloat (textStr));
-
- GetDItem (askBox, iFieldOfView, &iType, &iHandle, &iRect);
- GetIText (iHandle, textStr);
- if (textStr[0] == 0) boxDone = false;
- fieldOfView = Float2Fix(StringToFloat (textStr));
-
- GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
- if (GetCtlValue ((ControlHandle) iHandle)) movieType = kStandardObject;
- GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
- if (GetCtlValue ((ControlHandle) iHandle)) movieType = kOldNavigableMovieScene;
- GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
- if (GetCtlValue ((ControlHandle) iHandle)) movieType = kObjectInScene;
-
- initialHPan = startHPan;
- initialVPan = startVPan;
- if (theInstance)
- {
- GetMovieNextInterestingTime (theInstance->movie, nextTimeMediaSample, 0, nil, 0, 1, nil, &frameDur);
- posterViewTime = MCGetCurrentTime (theInstance->movieController, nil);
- }
-
- if(boxDone)
- {
- err = StuffQTVRObjectFileFormat1x0 ( movieType,
- frameDur,
- numberOfColumns,
- numberOfRows,
- loopSize,
- loopTicks,
- startHPan,
- endHPan,
- startVPan,
- endVPan,
- fieldOfView,
- initialHPan,
- initialVPan,
- &fileFormat);
- if(err)
- {
- boxDone = false;
- }
- else
- {
- gPrefInf.objectInfo = fileFormat;
- if (theInstance)
- {
- ConvertTimeToPanUtil (posterViewTime,
- fileFormat.frameDuration,
- fileFormat.numberOfColumns,
- fileFormat.numberOfRows,
- fileFormat.loopSize,
- fileFormat.startHPan,
- fileFormat.endHPan,
- fileFormat.startVPan,
- fileFormat.endVPan,
- &initialHPan,
- &initialVPan);
- gPrefInf.objectInfo.initialHPan = fileFormat.initialHPan = initialHPan;
- gPrefInf.objectInfo.initialVPan = fileFormat.initialVPan = initialVPan;
- }
- }
- }
- else
- {
- // Only reson for a failure at this point is a missing parameter
- UserMessage("\pYou must fill in values for all parameters.");
- }
-
-
- if(boxDone && applyValues) SetQTVRObjectFileFormat1x0 (theInstance->movie,
- theInstance->movieResFile,
- theInstance->movieResID,
- theInstance->spec,
- posterViewTime,
- &fileFormat);
- }
- break;
- }
- }
-
-
-
-
-
- DisposeDialog (askBox);
- DisposeRoutineDescriptor(filterUPP);
- DisposeRoutineDescriptor(outlineUPP);
- SetGWorld (saveGW,saveGD);
-
- // Be really safe. Close and open the movie again so the user can verify if anything is wrong.
- if ((hitItem == iOK) && (err == noErr) && theInstance) {
- FSSpec movieSFFile = theInstance->spec; // Make a copy since we will close the window
- CloseMovie (FrontWindow()); // We know there is a FrontWindow
- err = OpenMovie (&movieSFFile);
- }
- // BTW, the user should set the startup view after they have entered the nav data.
- if(hitItem == iCancel) err = 1;
- return (err);
- }
-
-
-
- pascal Boolean ModalFilter(DialogPtr theDlg,EventRecord *theEvent,short *itemHit)
- {
- switch(theEvent->what)
- {
- case mouseDown:
- {
- WindowPtr whichWindow;
- short int thePart;
-
- thePart = FindWindow(theEvent->where, &whichWindow);
- if(thePart == inDrag && whichWindow == theDlg)
- {
- DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
- return true;
- }
- return false;
- }
-
- break;
- case keyDown:
- {
- char theKey;
- Handle iHandle;
- short iType;
- Rect iRect;
-
- theKey = (theEvent->message & charCodeMask);
- if(theKey == 0x03 || theKey == 0x0D)
- {
- *itemHit = iOK;
- GetDItem (theDlg, iOK, &iType, &iHandle, &iRect);
- HiliteControl ((ControlHandle)iHandle, true);
- Delay(8,nil);
- HiliteControl ((ControlHandle)iHandle, false);
- return true;
- }
- if((theKey == '.' && ((theEvent->modifiers & cmdKey) != 0) ) || theKey == 0x1b)
- {
- GetDItem (theDlg, iCancel, &iType, &iHandle, &iRect);
- HiliteControl ((ControlHandle)iHandle, true);
- Delay(8,nil);
- HiliteControl ((ControlHandle)iHandle, false);
- *itemHit = iCancel;
- return true;
- }
- }
- break;
- case updateEvt:
- BeginUpdate (theDlg);
- DrawDialog(theDlg);
- EndUpdate (theDlg);
- return false;
- break;
- }
-
- return false;
- }
-
-
-
- pascal void OutlineOK(WindowPtr theDlg,short theItem )
- {
- Rect iRect;
- Handle iHndl;
- short iType;
- Point theOff = {0,0};
- GWorldPtr saveGW;
- GDHandle saveGD;
-
- GetGWorld(&saveGW, &saveGD);
- SetGWorld((GWorldPtr)theDlg,nil);
- GetDItem (theDlg, theItem, &iType, &iHndl, &iRect );
- InsetRect( &iRect, -4,-4);
- PenSize( 3,3 );
- FrameRoundRect( &iRect, 16,16 );
- PenSize( 1,1 );
- SetGWorld (saveGW,saveGD);
- }
-
-